Imports System.Data.SqlClient

Friend Class DBWaitStatelog
    Inherits DBBase

    Public Sub Load( _
        ByRef oObject As SQLAutoDocLib.WaitStateLog)

        Dim sSQL As String = "select"
        sSQL = sSQL & "     [DatabaseID],"
        sSQL = sSQL & "     [SessionID],"

        sSQL = sSQL & "     [Wait_Type],"
        sSQL = sSQL & "     [Requests],"
        sSQL = sSQL & "     [Wait_Time],"
        sSQL = sSQL & "     [Signal_Wait_Time],"
        sSQL = sSQL & "     [CreateDate]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     WaitStateHistory"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        Dim oData As DataTable = MyBase.ExecuteReadToDataTable(sSQL)

        If oData.Rows.Count > 0 Then
            With oData.Rows(0)
                oObject.DatabaseID = .Item("DatabaseID")
                oObject.SessionID = .Item("SessionID")

                oObject.WaitState_WaitType = .Item("Wait_Type")
                oObject.WaitState_Requests = .Item("Requests")
                oObject.WaitState_Wait_Time = .Item("Wait_Time")
                oObject.WaitState_Signal_Wait_Time = .Item("Signal_Wait_Time")

                oObject.CreateDate = .Item("CreateDate")
            End With
        End If

        oData.Dispose()
    End Sub

    Public Sub Add(ByRef oObject As SQLAutoDocLib.WaitStateLog)

        Dim sSQL As String = "insert into WaitStateHistory ("
        sSQL = sSQL & "     [ID],"
        sSQL = sSQL & "     [DatabaseID],"
        sSQL = sSQL & "     [SessionID],"

        sSQL = sSQL & "     [Wait_Type],"
        sSQL = sSQL & "     [Requests],"
        sSQL = sSQL & "     [Wait_Time],"
        sSQL = sSQL & "     [Signal_Wait_Time],"

        sSQL = sSQL & "     [CreateDate]) values ("

        sSQL = sSQL & ValueToDBValue(oObject.ID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.DatabaseID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.SessionID) & ","

        sSQL = sSQL & ValueToDBValue(oObject.WaitState_WaitType) & ","
        sSQL = sSQL & ValueToDBValue(oObject.WaitState_Requests) & ","
        sSQL = sSQL & ValueToDBValue(oObject.WaitState_Wait_Time) & ","
        sSQL = sSQL & ValueToDBValue(oObject.WaitState_Signal_Wait_Time) & ","

        sSQL = sSQL & ValueToDBValue(oObject.CreateDate) & ")"

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Delete(ByRef oObject As SQLAutoDocLib.WaitStateLog)
        Dim sSQL As String = "delete from WaitStateHistory"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub
End Class
